/*************************************************************************************
*Copyright (c) 2011, Intel Mobile Communications GmbH. 
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without
*modification, are permitted provided that the following conditions are met:
*    * Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*    * Neither the name of the <organization> nor the
*      names of its contributors may be used to endorse or promote products
*      derived from this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL INTEL MOBILE COMMUNICATIONS GMBH. BE LIABLE FOR ANY
*DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
*ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************************/



#include "cef_usecase.h"
using namespace std;
cef_usecase::cef_usecase()
{
	domain_operating_points=NULL;	
	initiators=NULL;
	name="default";
	id=NULL;
	weight=1;
}

cef_usecase::cef_usecase(string n,unsigned i,vector<pair<unsigned,unsigned>*>* d,double w,vector<cef_initiator*>* in): name(n), id(i) 
{
	domain_operating_points=d;
	initiators=in;
	weight=w;
}

cef_usecase::~cef_usecase()
{
	if(domain_operating_points)
	{
		for(unsigned i=0;i<domain_operating_points->size();i++)
		{
			delete (*domain_operating_points)[i];
		}
		delete domain_operating_points;
	}
	if(initiators)
	{
		for(unsigned i=0;i<initiators->size();i++)
		{
			delete (*initiators)[i];
		}
		delete initiators;
	}
}

vector<pair<unsigned,unsigned>*>* cef_usecase::getDOPs()
{
	return domain_operating_points;
}

vector<cef_initiator*>* cef_usecase::getInitiators()
{
	return initiators;
}
pair<unsigned,unsigned>* cef_usecase::getDOP(unsigned i)
{
	if(domain_operating_points) return (*domain_operating_points)[i];	
	return NULL;
}
cef_initiator* cef_usecase::getInitiator(unsigned i)
{
	if(initiators) return (*initiators)[i];
	return NULL;

}
string cef_usecase::getName()
{
	return name;
}
unsigned cef_usecase::getID()
{
	return id;
}

double cef_usecase::getWeight()
{
	return weight;
}

void cef_usecase::setDOPs(vector<pair<unsigned,unsigned>*>* d)
{
	domain_operating_points=d;	
}

void cef_usecase::setInitiators(vector<cef_initiator*>* i)
{
	initiators=i;
}
void cef_usecase::setName(string n)
{
	name=n;
}
void cef_usecase::setID(unsigned i)
{
	id=i;
}
void cef_usecase::addDOP(pair<unsigned,unsigned>* d)
{
	if(domain_operating_points==NULL) domain_operating_points=new vector<pair<unsigned,unsigned>*>();	
	domain_operating_points->push_back(d);
}
void cef_usecase::addInitiator(cef_initiator* i)
{
	if(domain_operating_points==NULL) initiators=new vector<cef_initiator*>();	
	initiators->push_back(i);
}
void cef_usecase::setWeight(double w)
{
	weight=w;
}
#ifdef _DEBUG
void cef_usecase::print()
{
	cout<<"CEF Usecase\nBEGIN\n";
	cout<<"Name: "<<name<<" ID: "<<id;
	if(initiators)
	{
		for(unsigned i=0;i<initiators->size();i++)
		{
			(*initiators)[i]->print();
		}
	}
	if(domain_operating_points)
	{
		cout<<"Domain Operating Points: ";
		for(unsigned i=0;i<domain_operating_points->size();i++)
		{
			cout<<"("<<(*domain_operating_points)[i]->first<<","<<(*domain_operating_points)[i]->second<<") ";
		}
		cout<<endl;
	}
	cout<<"END\n";
}
#endif
